//
//  AWMessage.h
//  AtWork2
//
//  Created by lucas on 15/4/22.
//  Copyright (c) 2015年 Foreveross. All rights reserved.
//

#import "AWMessageConstants.h"

/**
 *   消息类型。
 */
typedef NS_ENUM(NSUInteger, AWMessageType) {
    
    /** 命令消息，例如：MDM；多终端登录踢人消息等 */
    AWMessageTypeCmd     = 20,
    
    /** 请求消息 */
    AWMessageTypeReq     = 21,
    
    /** 请求响应消息 */
    AWMessageTypeResp    = 22,
    
    /** 回执消息 */
    AWMessageTypeAck     = 31,
    
    /** 聊天消息 文本、图片、语音等消息 */
    AWMessageTypeChat    = 41,
    
    /** 通知消息，例如：群加人 */
    AWMessageTypeNotice  = 51,
    
    /** VOIP */
    AWMessageTypeVoip    = 61,
    
    /** 服务号消息 */
    AWMessageTypeServeNo = 71,
    
    /** 自定义消息 */
    AWMessageTypeCustom  = 99
};

extern inline AWMessageType parseWithMessageType(NSString *type);
extern inline UInt64 deliveryTime();
extern NSString * identifier();

/**
 *  消息
 */
@interface AWMessage : NSObject

@property (nonatomic, assign) AWMessageType messageType;

//TODO: 暂时为可修改 ，后面修改为只可读取。
/** 发送方 */
@property (nonatomic, copy) NSString *from;

/** 接收方 */
@property (nonatomic, copy) NSString *to;

/** 消息体 */
//@property (nonatomic, strong, readonly) NSDictionary *body;

// TODO: 暂时修改为可读可写。
/** 消息标识 */
@property (nonatomic, copy) NSString *deliveryId;

/** 消息发送时间(毫秒值) */
@property (nonatomic, assign) UInt64 deliveryTime;

+ (instancetype)messageWithFrom:(NSString *)from
                             to:(NSString *)to
                    messageType:(AWMessageType)messageType;

- (instancetype)initWithFrom:(NSString *)from
                          to:(NSString *)to
                 messageType:(AWMessageType)messageType;

+ (instancetype)messageWithDeliveryId:(NSString *)deliveryId
                                 from:(NSString *)from
                                   to:(NSString *)to
                         deliveryTime:(UInt64)deliveryTime
                          messageType:(AWMessageType)messageType;

- (instancetype)initWithDeliveryId:(NSString *)deliveryId
                                 from:(NSString *)from
                                   to:(NSString *)to
                         deliveryTime:(UInt64)deliveryTime
                          messageType:(AWMessageType)messageType;

- (instancetype)initWithMessageType:(AWMessageType)messageType;

+ (instancetype)messageWithMessageType:(AWMessageType)messageType;

+ (instancetype)messageWithDictionary:(NSDictionary *)aMessage;

- (instancetype)initWithDictionary:(NSDictionary *)aMessage;

/**
 *  对象构建成Data。
 */
- (NSData *)buildData;

- (void)bodyWithKey:(NSString *)key value:(id)value;

- (void)bodyWithOther:(NSDictionary *)other;

- (void)bodyRemoveWithKey:(NSString *)key;

- (id)bodyValueForKey:(NSString *)key;

- (NSDictionary *)body;

/**
 *  发送。
 */
- (void)send;

@end
